<template>
  <header class="header">
    <div class="header-content">
      <h4>我的应用</h4>
      <div v-if="isLoggedIn" class="user-info">
        <span>欢迎, {{ username }}</span>
        <button @click="logout">登出</button>
      </div>
      <div v-else>
        <button @click="login">登录</button>
      </div>
    </div>
  </header>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const isLoggedIn = ref<boolean>(false);
const username = ref<string>('张三');

const login = () => {
  isLoggedIn.value = true;
};

const logout = () => {
  isLoggedIn.value = false;
};
</script>

<style scoped>
.header {
  background-color: #42b983;
  color: white;
  padding: 0px 20px;
  position: sticky;
  top: 0;left: 0;right: 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

button {
  padding: 5px 10px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
</style>